package org.example.test;

/**
 * @author : yuhuan.wu
 * @date : 2021/11/1
 * @description : 效率测试，但是这个连续的业务场景几乎不可能相似的场景
 */
public class test {

    public static void main(String[] args) throws Exception
    {
        doRegular();
        doReflection();
    }

    public static void doRegular() {
        long start = System.currentTimeMillis();
        for (int i=0; i<1000000; i++)
        {
            User a = new User();
            a.doSomeThing();
        }
        System.out.println("使用构造函数创建耗时：" + (System.currentTimeMillis() - start));
    }

    public static void doReflection() throws Exception
    {
        long start = System.currentTimeMillis();
        for (int i=0; i<1000000; i++)
        {
            User a = (User) Class.forName("org.example.test.User").newInstance();
            a.doSomeThing();
        }
        System.out.println("使用java反射创建耗时：" + (System.currentTimeMillis() - start));
    }


}
